<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      class Person {
        /*
          构造方法
          1. new 类的时候被自动调用
          2. 构造方法返回内部this对象，给p1赋值
          3. 通过this对象设置p1属性
        */
        constructor() {
          // this = {};
          this.username = "jack";
          this.age = 20;
          // return this;
        }
        say() {
          console.log("hello");
        }
        add(a, b) {
          console.log(a + b);
        }
      }
      // const p1 = new constructor()
      // p1 = constructor{this}
      const p1 = new Person(); // 调用 constructor
      console.log(p1.username);
      p1.say();
      p1.add(1, 2);
    </script>
  </body>
</html>
